{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "91c6a7ef",
   "metadata": {},
   "source": [
    "# Cassandra Chat Message History\n",
    "\n",
    "This notebook goes over how to use Cassandra to store chat message history.\n",
    "\n",
    "Cassandra is a distributed database that is well suited for storing large amounts of data. \n",
    "\n",
    "It is a good choice for storing chat message history because it is easy to scale and can handle a large number of writes.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "47a601d2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# List of contact points to try connecting to Cassandra cluster.\n",
    "contact_points = [\"cassandra\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "d15e3302",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain.memory import CassandraChatMessageHistory\n",
    "\n",
    "message_history = CassandraChatMessageHistory(\n",
    "    contact_points=contact_points, session_id=\"test-session\"\n",
    ")\n",
    "\n",
    "message_history.add_user_message(\"hi!\")\n",
    "\n",
    "message_history.add_ai_message(\"whats up?\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "64fc465e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[HumanMessage(content='hi!', additional_kwargs={}, example=False),\n",
       " AIMessage(content='whats up?', additional_kwargs={}, example=False)]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "message_history.messages"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
